home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / edit / xvisrc.zip / IBMPC_A.ASM < prev    next >
Assembly Source File  |  1992-07-28  |  20KB  |  966 lines

  1. ; Copyright (c) 1990,1991,1992 Chris and John Downey
  2. _TEXT    segment word public 'CODE'
  3.     db    "@(#)ibmpc_a.asm    2.1 (Chris & John Downey) 7/29/92"
  4.     db    0
  5. _TEXT    ends
  6.  
  7. ;***
  8. ;
  9. ; program name:
  10. ;    xvi
  11. ; function:
  12. ;    PD version of UNIX "vi" editor, with extensions.
  13. ; module name:
  14. ;    ibmpc_a.asm
  15. ; module function:
  16. ;    Assembly language part of terminal interface module for IBM PC
  17. ;    compatibles running MS-DOS.
  18. ;
  19. ;    This code has been assembled with Microsoft's Macro Assembler
  20. ;    (MASM) version 5.1, & is compatible with code generated by
  21. ;    MS-DOS C compilers using the normal large memory model calling
  22. ;    conventions. This includes the Microsoft & Zortech compilers.
  23. ;
  24. ;    If we're running on a mono system, or one with an EGA or VGA,
  25. ;    & we were started in a text mode, we can achieve much faster
  26. ;    display output by writing directly to the frame buffer; we can
  27. ;    also save the previous screen contents & restore them when we
  28. ;    exit or run a sub-shell, which can be useful. If we have a
  29. ;    CGA, or we were started in a graphics mode, we just use the
  30. ;    functions supplied by the PC BIOS, which are slower, but good
  31. ;    enough for most purposes. On a modern 80386-based system, the
  32. ;    difference in speed is hardly noticeable.
  33. ; history:
  34. ;
  35. ;    STEVIE - ST Editor for VI Enthusiasts, Version 3.10
  36. ;    Originally by Tim Thompson (twitch!tjt)
  37. ;    Extensive modifications by Tony Andrews (onecom!wldrdg!tony)
  38. ;    Heavily modified by Chris & John Downey
  39. ;***
  40.  
  41. include 8086mm.inc
  42.  
  43. ;
  44. ; If SWAPSCREEN is defined, we attempt to save the previous screen
  45. ; image & restore it when we exit or run another process. If you don't
  46. ; want this to happen, just comment out the line below.
  47. ;
  48. SWAPSCREEN    equ    1
  49.  
  50. ;
  51. ; If you don't want mouse input handling, comment out the line below.
  52. ;
  53. MOUSE        equ    1
  54.  
  55.     C_extern _malloc
  56.     C_extern _cparams
  57.  
  58.     public    _alert
  59.     public    _erase_display
  60.     public    _erase_line
  61.     public    _flush_output
  62.     public    _hidemouse
  63.     public    _mousestatus
  64.     public    _outchar
  65.     public    _outstr
  66.     public    _scroll_up
  67.     public    _scroll_down
  68.     public    _set_colour
  69.     public    _showmouse
  70.     public    _tty_endv
  71.     public    _tty_goto
  72.     public    _tty_open
  73.     public    _tty_startv
  74.  
  75. ;
  76. ; Segment addresses for PC text mode frame buffer.
  77. ;
  78. VMONOSEG    =    0b000h    ; Mono frame buffer.
  79. VCOLOURSEG    =    0b800h    ; Colour frame buffer.
  80.  
  81. ;
  82. ; BIOS video functions.
  83. ;
  84. vbios        macro    ahval, alval
  85.     ifnb    <ahval>
  86.         ifnb <alval>
  87.         mov    ax, (ahval shl 8) + alval
  88.         else
  89.         mov    ah, ahval
  90.         endif
  91.     endif
  92.         int    10h
  93.         endm
  94. ;
  95. ; BIOS video function numbers.
  96. ;
  97. B_MOVECURSOR    =    2    ; Move cursor.
  98. B_UPSCROLL    =    6    ; Scroll window up.
  99. B_DOWNSCROLL    =    7    ; Scroll window down.
  100. B_WRITECHAR    =    9    ; Write character & attribute at
  101.                 ; current position.
  102. B_TTYWRITE    =    0eh    ; Teletype-style write.
  103. B_GETMODE    =    0fh    ; Get video mode.
  104. B_SETPALETTE    =    10h    ; Set palette registers.
  105. B_EGACGEN    =    11h    ; EGA character generator.
  106. B_VCONFIG    =    12h    ; Video subsystem configuration.
  107.  
  108. ;
  109. ; Subfunction (of function 10h) for setting overscan register.
  110. ;
  111. B_OVERSCAN    =    1
  112.  
  113. ;
  114. ; Subfunctions for EGA character generator.
  115. ;
  116. B_EGATEST    =    30h
  117. B_8X8FONT    =    12h
  118. B_8X14FONT    =    11h
  119.  
  120. ;
  121. ; BIOS function to use alternate print screen routine.
  122. ;
  123. altpscreen    macro
  124.         mov    bl, 20h
  125.         vbios    B_VCONFIG
  126.         endm
  127.  
  128. ;
  129. ; BIOS function to get equipment list.
  130. ;
  131. biosequip    macro
  132.         int    11h
  133.         endm
  134. ;
  135. ; Value returned by biosequip (in ax) to indicate a mono display.
  136. ;
  137. EQUIP_MONO    =    30h
  138.  
  139. ;
  140. ; Default number of rows in text modes.
  141. ;
  142. DEF_T_ROWS    =    25
  143.  
  144. ;
  145. ; Video modes.
  146. ;
  147. BWT25X80    =    2    ; 25 x 80 black & white (CGA) text.
  148. CT25X80        =    3    ; 25 x 80 colour text.
  149. MT25X80        =    7    ; 25 x 80 monochrome (MDA) text.
  150.  
  151. ;
  152. ; I/O ports.
  153. ;
  154. TIMER_2        =    42h    ; Timer channel 2.
  155. TIMER_3        =    43h    ; Timer channel 3.
  156. PORT_B        =    61h    ; 8255 port B.
  157.  
  158. ;
  159. ; Interrupt used by Microsoft mouse driver.
  160. ;
  161. MSMINT        =    33h
  162.  
  163. ;
  164. ; Call mouse driver.
  165. ;
  166. msmouse        macro    funcnum
  167.     ifnb    <funcnum>
  168.         mov    ax, funcnum
  169.     endif
  170.         int    MSMINT
  171.         endm
  172. ;
  173. ; Mouse driver function numbers.
  174. ;
  175. MSM_SHOW    =    1
  176. MSM_HIDE    =    2
  177. MSM_GETSTATUS    =    3
  178. MSM_SETYLIMITS    =    8
  179.  
  180. ;
  181. ; Values for mouseflag.
  182. ;
  183. MF_NOMOUSE    =    -1
  184. MF_INITIAL    =    0
  185. MF_OK        =    1
  186. MF_VISIBLE    =    2
  187.  
  188. ;
  189. ; Segment containing interrupt vector table.
  190. ;
  191. INTVECTAB    segment at 0
  192.         ;
  193.         ; Vector used by Microsoft mouse driver.
  194.         ;
  195.         org (MSMINT * 4)
  196. msvecoff    dw    ?
  197. msvecseg    dw    ?
  198. INTVECTAB    ends
  199.  
  200. ;
  201. ; BIOS variable data segment.
  202. ;
  203. BVSEG        =    40h
  204.  
  205. BIOSDATA    segment at BVSEG
  206.         ;
  207.         ; Low word of timer variable.
  208.         ;
  209.         org    6ch
  210. b_timer_low    dw    ?
  211.         ;
  212.         ; Variable giving number of screen rows - 1.
  213.         ;
  214.         org    84h
  215. b_rowsvar    db    ?
  216. BIOSDATA    ends
  217.  
  218. _TEXT        segment word public 'CODE'
  219.         assume    nothing
  220.         assume    cs: _TEXT
  221.  
  222.         even
  223.     ifdef    SWAPSCREEN
  224. saveptr        label    dword    ; Pointer to saved screen image.
  225. svboff        dw    0
  226. svbseg        dw    0
  227. scrwords    dw    ?    ; Number of 2-byte words in saved
  228.                 ; screen image.
  229.     endif    ; SWAPSCREEN
  230. vbase        dw    0    ; Segment address of frame buffer. If
  231.                 ; this is 0, we don't access the frame
  232.                 ; buffer directly.
  233. vcolumn        label    byte
  234. vpos        dw    ?    ; Virtual screen position.
  235. scrsize        label    word    ; Screen dimensions.
  236. ncolumns    db    ?    ; Low byte of scrsize.
  237. nrows        db    ?    ; High byte of scrsize.
  238. writemethod    dw    offset bioswrite
  239.                 ; Pointer to function we use for
  240.                 ; outputting characters to the screen.
  241. startmode    db    ?
  242. ega        db    0    ; Flag indicating presence of EGA/VGA.
  243. vcolour        db    ?    ; Virtual colour.
  244.     ifdef    MOUSE
  245. mouseflag    db    MF_INITIAL
  246.                 ; This is changed by _tty_startv to
  247.                 ; MF_OK if we have a mouse driver
  248.                 ; installed, or MF_NOMOUSE if we
  249.                 ; haven't.
  250.     else    ; MOUSE
  251. mouseflag    db    MF_NOMOUSE
  252.     endif    ; MOUSE
  253.  
  254.     ifdef    SWAPSCREEN
  255.     ;
  256.     ; These routines deal with saving the previous screen image &
  257.     ; restoring it.
  258.     ;
  259. savescreen:
  260.         cmp    vbase, 0
  261.         je    dontcopy
  262.         push    si
  263.         push    di
  264.         push    ds
  265.         les    di, saveptr
  266.         mov    ax, es
  267.         or    ax, di
  268.         jz    cps_pop
  269.         mov    ds, vbase
  270.         clear    si
  271.         jmp short copyscreen
  272.  
  273. restorescreen    proc    near
  274.         cmp    vbase, 0
  275.         je    dontcopy
  276.         push    si
  277.         push    di
  278.         push    ds
  279.         mov    es, vbase
  280.         clear    di
  281.         lds    si, saveptr
  282.         mov    ax, ds
  283.         or    ax, si
  284.         jz    cps_pop
  285. copyscreen:
  286.         mov    cx, scrwords
  287.         cld
  288.         rep    movsw
  289. cps_pop:
  290.         pop    ds
  291.         pop    di
  292.         pop    si
  293. dontcopy:
  294.         ret
  295. restorescreen    endp
  296.     endif    ; SWAPSCREEN
  297.  
  298.         even
  299. _flush_output:
  300.         ;
  301.         ; void flush_output(void);
  302.         ;
  303.         ; Update real cursor position.
  304.         ;
  305.         push    bp
  306.         mov    dx, vpos
  307.         clear    bh        ; Display page 0.
  308.         vbios    B_MOVECURSOR
  309.         pop    bp
  310.         C_ret
  311.  
  312.         even
  313. _erase_line:
  314.         ;
  315.         ; void erase_line(void);
  316.         ;
  317.         ; Erase to end of line.
  318.         ;
  319.         ; Don't update cursor position.
  320.         ;
  321.         mov    cl, ncolumns    ; Get width of screen.
  322.         mov    al, vcolumn    ; Get current column.
  323.         sub    cl, al        ; Number of spaces to write ...
  324.         jz    noerase        ; ... except if it's 0 ...
  325.         clear    ch
  326.         mov    al, ' '
  327.         cld
  328.         call    [writemethod]
  329. noerase:
  330.         C_ret
  331.  
  332. _erase_display:
  333.         ;
  334.         ; void erase_display(void);
  335.         ;
  336.         ; Erase entire display by using BIOS scroll screen
  337.         ; function to scroll all the lines in the display.
  338.         ;
  339.         ; Don't update cursor position.
  340.         ;
  341.         call    _cparams    ; This is in ibmpc_c.c.
  342.         mov    bh, al        ; Get colour for blank screen.
  343.         push    bp
  344.         clear    cx        ; Top left row & column (0).
  345.         mov    al, nrows    ; Number of lines (0).
  346.         mov    dx, scrsize
  347.         dec    dh        ; Bottom right row.
  348.         dec    dl        ; Bottom right column.
  349.         vbios    B_UPSCROLL
  350.         pop    bp
  351.         C_ret
  352.  
  353.         even
  354. _showmouse:
  355.         ;
  356.         ; void showmouse(void);
  357.         ;
  358.         ; Show mouse cursor.
  359.         ;
  360.         ; If we don't seem to have a mouse driver, or we think
  361.         ; the cursor is already visible, don't do anything.
  362.         ;
  363.         cmp    mouseflag, MF_OK
  364.         jne    m_invalid
  365.         mov    ax, MSM_SHOW
  366.         mov    mouseflag, MF_VISIBLE
  367. m_valid:
  368.         msmouse
  369. m_invalid:
  370.         C_ret
  371.  
  372.         even
  373. _hidemouse:
  374.         ;
  375.         ; void hidemouse(void);
  376.         ;
  377.         ; Hide mouse cursor.
  378.         ;
  379.         ; If we don't seem to have a mouse driver, or we don't
  380.         ; think the cursor is visible, don't do anything.
  381.         ;
  382.         cmp    mouseflag, MF_VISIBLE
  383.         jne    m_invalid
  384.         mov    ax, MSM_HIDE
  385.         mov    mouseflag, MF_OK
  386.         jmp short m_valid
  387.  
  388. _mousestatus:
  389.         ;
  390.         ; unsigned mousestatus(unsigned *xpos, unsigned *ypos);
  391.         ;
  392.         ; Return mouse button status, with current mouse
  393.         ; co-ordinates in *xpos & *ypos.
  394.         ;
  395.         push    bp
  396.         mov    bp, sp
  397.         cmp    mouseflag, MF_OK
  398.         jge    getstatus    ; if it's MF_OK or MF_VISIBLE
  399.         clear    ax        ; Button status = 0.
  400.         cwd            ; y co-ordinate = 0.
  401.         mov    cx, ax        ; x co-ordinate = 0.
  402.         jmp short ms_finish
  403. getstatus:
  404.         msmouse MSM_GETSTATUS
  405.         mov    ax, bx        ; Return button status in ax.
  406. ms_finish:
  407.         ;
  408.         ; Stack frame:
  409.         ;
  410.         ;   bp + CPTRSIZE + DPTRSIZE + 2
  411.         ;        ypos pointer
  412.